<script>
  function delay(ms) {
    return new Promise(function (resolve) {
      setTimeout(() => resolve(), ms)
    })
  }

  const begin = Date.now() // 开始时间
  const p1 = delay(1000).then(() => {
    console.log('p1完成', Date.now() - begin)
    return 'a'
    // throw 'a'
  })
  const p2 = delay(200).then(() => {
    console.log('p2完成', Date.now() - begin)
    // return 'b'
    throw 'b'
  })
  const p3 = delay(1500).then(() => {
    console.log('p3完成', Date.now() - begin)
    // return 'c'
    throw 'c'
  })
  // const p4 = new Promise(() => {})

  // const all = Promise.all([p1, p2, p3, Promise.resolve({name: '张三'})]).then((results) => {
  //   console.log('all完成', results, Date.now() - begin)
  // }).catch(e => {
  //   console.log('all失败', e, Date.now() - begin)
  // })

  // const race = Promise.race(
  //   [p1, p2, p3])
  // .then((results) => {
  //   console.log('race完成', results, Date.now() - begin)
  // }).catch(e => {
  //   console.log('race失败', e, Date.now() - begin)
  // })
  // const any = Promise.any(
  //   [p1, p2, p3])
  // .then((results) => {
  //   console.log('any完成', results, Date.now() - begin)
  // }).catch(e => {
  //   // debugger
  //   console.log('any失败', e, Date.now() - begin)
  // })
  const allSettled = Promise.allSettled(
    [p1, p2, p3])
  .then((results) => {
    console.log('allSettled完成', results, Date.now() - begin)
  }).catch(e => {
    // debugger
    console.log('allSettled失败', e, Date.now() - begin)
  })
</script>